package com.sina.weibo;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.sina.weibo.models.Comment;
import com.sina.weibo.models.User;
import com.sina.weibo.view.CommentItemView;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommentBlog extends BaseActivity
  implements View.OnClickListener
{
  public static final int ADD_COMMENT = 0;
  public static final String COMMENT_ID = "COMMENT_ID";
  public static final String COMMENT_MODE = "MODE";
  public static final String COMMENT_NICK = "NICK";
  public static final String COMMENT_UID = "COMMENT_UID";
  public static final int MODE_REPLY_COMMENT = 0;
  public static final int MODE_REPLY_WEIBO = 1;
  private static final int PAGE_NUM = 20;
  String ctNick = "";
  private boolean isAsNewMblog = 0;
  String mBlogId;
  String mBlogUid;
  boolean mButtonClickable = 1;
  String mCacheDir;
  String mComment;
  Comment mCurCmt = null;
  private String mCurrentCommentId = "";
  private int mExpectItem = -1;
  int mFlag = 1;
  private List<Comment> mList;
  private ListView mLvCmt;
  private int mMode = 0;
  private int mPage = 1;
  private String mPassCommentId = "";
  private String mPassCommentUID = "";
  private String mPassword;
  CustomToast mPgToast;
  PostCommentTask mPostTask;
  boolean mPostTaskFree = 1;
  String mSubString = "";
  FetchDataTask mTask;
  boolean mTaskFree = 1;
  int mTotal = 0;
  private User mUser;
  private String mUsername;

  private void closeFthProgress(List<Comment> paramList)
  {
    if (paramList != null)
      if ((this.mList == null) || (this.mList.size() == 0))
      {
        this.mList = paramList;
        if (this.mList.size() <= 0)
          break label324;
        this.mLvCmt.setVisibility(0);
        this.mLvCmt.setFocusable(1);
        this.mLvCmt.setFocusableInTouchMode(1);
        label66: if (this.mList != null)
          break label335;
        int i = 0;
      }
    while (true)
    {
      ((WeiboCmtListAdapter)this.mLvCmt.getAdapter()).refresh();
      return;
      if (paramList.size() > 0)
      {
        Iterator localIterator1 = paramList.iterator();
        while (true)
        {
          if (!localIterator1.hasNext())
          {
            List localList1 = this.mList;
            Comment[] arrayOfComment1 = new Comment[0];
            Comment[] arrayOfComment2 = (Comment[])localList1.toArray(arrayOfComment1);
            CommentBlog.3 local3 = new CommentBlog.3(this);
            Arrays.sort(arrayOfComment2, local3);
            ArrayList localArrayList = new ArrayList();
            this.mList = localArrayList;
            int j = 0;
            while (true)
            {
              int k = arrayOfComment2.length;
              if (j >= k)
                break;
              List localList2 = this.mList;
              Comment localComment1 = arrayOfComment2[j];
              boolean bool1 = localList2.add(localComment1);
              j += 1;
            }
          }
          Comment localComment2 = (Comment)localIterator1.next();
          Iterator localIterator2 = this.mList.iterator();
          String str1;
          String str2;
          do
          {
            if (!localIterator2.hasNext())
            {
              boolean bool2 = this.mList.add(localComment2);
              break;
            }
            Comment localComment3 = (Comment)localIterator2.next();
            str1 = localComment2.cmtid;
            str2 = localComment3.cmtid;
          }
          while (!str1.equals(str2));
        }
      }
      int m = this.mPage - 1;
      this.mPage = m;
      break;
      label324: this.mLvCmt.setVisibility(4);
      break label66;
      label335: int n = this.mList.size();
      continue;
      String str3 = getString(2131427376);
      Toast.makeText(this, str3, 0).show();
      if (this.mList != null)
        continue;
      this.mLvCmt.setVisibility(4);
    }
  }

  private void closeProgress(Boolean paramBoolean)
  {
    if (paramBoolean.booleanValue())
    {
      String str1 = getString(2131427478);
      Toast.makeText(this, str1, 0).show();
      finish();
    }
    while (true)
    {
      return;
      String str2 = getString(2131427479);
      Toast.makeText(this, str2, 0).show();
    }
  }

  private void doItemMenu(String paramString)
  {
    Resources localResources = getResources();
    String str1 = localResources.getString(2131427512);
    if (paramString.equals(str1))
    {
      List localList1 = this.mList;
      int i = this.mExpectItem;
      Comment localComment1 = (Comment)localList1.get(i);
      this.mCurCmt = localComment1;
      String str2 = this.mBlogId;
      String str3 = this.mBlogUid;
      Comment localComment2 = this.mCurCmt;
      Intent localIntent1 = Utils.commentComment(this, str2, str3, localComment2);
      startActivity(localIntent1);
    }
    while (true)
    {
      return;
      String str4 = localResources.getString(2131427518);
      if (paramString.equals(str4))
      {
        Intent localIntent2 = new Intent(this, UserInfoActivity2.class);
        List localList2 = this.mList;
        int j = this.mExpectItem;
        String str5 = ((Comment)localList2.get(j)).cmtuid;
        Intent localIntent3 = localIntent2.putExtra("uid", str5);
        String str6 = StaticInfo.mUser.uid;
        Intent localIntent4 = localIntent2.putExtra("myuid", str6);
        Intent localIntent5 = localIntent2.putExtra("vip", 1);
        startActivity(localIntent2);
        continue;
      }
      if (!Utils.getWebPattern().matcher(paramString).matches())
        continue;
      Intent localIntent6 = new Intent("android.intent.action.VIEW");
      Uri localUri = Uri.parse(paramString);
      Intent localIntent7 = localIntent6.setData(localUri);
      startActivity(localIntent6);
    }
  }

  private void setAppTitle()
  {
    String str1 = getString(2131427347);
    StringBuilder localStringBuilder1;
    String str3;
    if (this.mUser != null)
    {
      String str2 = String.valueOf(str1);
      localStringBuilder1 = new StringBuilder(str2).append(" - ");
      str3 = this.mUser.nick;
    }
    StringBuilder localStringBuilder3;
    String str8;
    for (str1 = str3; ; str1 = str8)
    {
      String str4 = String.valueOf(str1);
      StringBuilder localStringBuilder2 = new StringBuilder(str4).append(" - ");
      String str5 = getString(2131427371);
      String str6 = str5;
      setTitle(str6);
      return;
      String str7 = String.valueOf(str1);
      localStringBuilder3 = new StringBuilder(str7).append(" - ");
      str8 = this.mUsername;
    }
  }

  private void showFthProgress()
  {
    CustomToast localCustomToast = Utils.createProgressCustomToast(2131427424, this);
    this.mPgToast = localCustomToast;
    this.mPgToast.show();
  }

  private void showItemMenu(List<CharSequence> paramList)
  {
    AlertDialog.Builder localBuilder1 = new AlertDialog.Builder(this);
    List<CharSequence> localList = paramList;
    AlertDialog.Builder localBuilder2 = localBuilder1.setTitle(2131427371);
    CharSequence[] arrayOfCharSequence1 = new CharSequence[0];
    CharSequence[] arrayOfCharSequence2 = (CharSequence[])localList.toArray(arrayOfCharSequence1);
    CommentBlog.4 local4 = new CommentBlog.4(this, localList);
    AlertDialog.Builder localBuilder3 = localBuilder1.setItems(arrayOfCharSequence2, local4);
    localBuilder1.create().show();
  }

  private void showProgress()
  {
    CustomToast localCustomToast = Utils.createProgressCustomToast(2131427419, this);
    this.mPgToast = localCustomToast;
    this.mPgToast.show();
  }

  protected void handleTitleBarEvent(int paramInt)
  {
    switch (paramInt)
    {
    default:
    case 0:
    case 1:
    }
    while (true)
    {
      return;
      String str1 = this.mBlogId;
      String str2 = this.mBlogUid;
      Intent localIntent = Utils.simpleComment(this, str1, str2);
      startActivityForResult(localIntent, 0);
      continue;
      finish();
    }
  }

  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    if ((paramInt1 == 0) && (paramInt2 == -1) && (this.mTaskFree) && (this.mTask != null))
    {
      FetchDataTask localFetchDataTask1 = new FetchDataTask(null);
      this.mTask = localFetchDataTask1;
      FetchDataTask localFetchDataTask2 = this.mTask;
      Integer[] arrayOfInteger = new Integer[1];
      Integer localInteger = Integer.valueOf(1);
      arrayOfInteger[0] = localInteger;
      AsyncTask localAsyncTask = localFetchDataTask2.execute(arrayOfInteger);
    }
  }

  public void onClick(View paramView)
  {
    if (!this.mButtonClickable);
    while (true)
    {
      return;
      super.onClick(paramView);
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setView(2130903048);
    String str1 = getString(2131427528);
    String str2 = getString(2131427371);
    String str3 = getString(2131427511);
    setTitleBar(1, str1, str2, str3);
    String str4 = getCacheDir().getPath();
    this.mCacheDir = str4;
    SharedPreferences localSharedPreferences1 = getSharedPreferences("weibo", 0);
    String str5 = localSharedPreferences1.getString("username", "");
    this.mUsername = str5;
    String str6 = localSharedPreferences1.getString("password", "");
    this.mPassword = str6;
    SharedPreferences localSharedPreferences2 = PreferenceManager.getDefaultSharedPreferences(this);
    User localUser = Utils.loadUserFile(this.mCacheDir);
    this.mUser = localUser;
    String str7 = getIntent().getStringExtra("id");
    this.mBlogId = str7;
    String str8 = getIntent().getStringExtra("uid");
    this.mBlogUid = str8;
    WeiboCmtListAdapter localWeiboCmtListAdapter = new WeiboCmtListAdapter();
    ListView localListView1 = (ListView)findViewById(2131623965);
    this.mLvCmt = localListView1;
    this.mLvCmt.setAdapter(localWeiboCmtListAdapter);
    ListView localListView2 = this.mLvCmt;
    CommentBlog.1 local1 = new CommentBlog.1(this);
    localListView2.setOnItemClickListener(local1);
    ListView localListView3 = this.mLvCmt;
    CommentBlog.2 local2 = new CommentBlog.2(this);
    localListView3.setOnScrollListener(local2);
    int i = getIntent().getIntExtra("MODE", 1);
    this.mMode = i;
    if (this.mMode == 0)
    {
      String str9 = getIntent().getStringExtra("NICK");
      this.ctNick = str9;
      String str10 = String.valueOf(getString(2131427435));
      StringBuilder localStringBuilder = new StringBuilder(str10).append("@");
      String str11 = this.ctNick;
      String str12 = str11 + ":";
      this.mSubString = str12;
      String str13 = getIntent().getStringExtra("COMMENT_ID");
      this.mPassCommentId = str13;
      String str14 = getIntent().getStringExtra("COMMENT_UID");
      this.mPassCommentUID = str14;
      this.mFlag = 2;
    }
  }

  protected void onPause()
  {
    super.onPause();
    if ((!this.mTaskFree) && (this.mTask != null) && (!this.mTask.isCancelled()))
    {
      if ((!this.mTaskFree) && (this.mPgToast != null))
        this.mPgToast.cancel();
      this.mTaskFree = 1;
      boolean bool1 = this.mTask.cancel(1);
    }
    if ((!this.mPostTaskFree) && (this.mPostTask != null) && (!this.mPostTask.isCancelled()))
    {
      if ((!this.mPostTaskFree) && (this.mPgToast != null))
        this.mPgToast.cancel();
      this.mPostTaskFree = 1;
      boolean bool2 = this.mPostTask.cancel(1);
    }
  }

  protected void onResume()
  {
    super.onResume();
    if (this.mBlogId != null)
    {
      if ((this.mList != null) || (!this.mTaskFree))
        break label69;
      FetchDataTask localFetchDataTask1 = new FetchDataTask(null);
      this.mTask = localFetchDataTask1;
      FetchDataTask localFetchDataTask2 = this.mTask;
      Integer[] arrayOfInteger = new Integer[1];
      Integer localInteger = Integer.valueOf(1);
      arrayOfInteger[0] = localInteger;
      AsyncTask localAsyncTask = localFetchDataTask2.execute(arrayOfInteger);
    }
    while (true)
    {
      return;
      label69: this.mLvCmt.setVisibility(0);
      ((WeiboCmtListAdapter)this.mLvCmt.getAdapter()).refresh();
    }
  }

  class FetchDataTask extends AsyncTask<Integer, Object, List<Comment>>
  {
    private FetchDataTask()
    {
    }

    protected List<Comment> doInBackground(Integer[] paramArrayOfInteger)
    {
      int i = paramArrayOfInteger[0].intValue();
      if (paramArrayOfInteger.length > 1)
        int j = paramArrayOfInteger[1].intValue();
      Object[] arrayOfObject1 = (Object[])0;
      try
      {
        if (CommentBlog.this.mUser == null)
        {
          Object[] arrayOfObject2 = new Object[1];
          Integer localInteger1 = Integer.valueOf(1);
          arrayOfObject2[0] = localInteger1;
          publishProgress(arrayOfObject2);
          CommentBlog localCommentBlog1 = CommentBlog.this;
          RPCHelper localRPCHelper1 = RPCHelper.getInstance(CommentBlog.this);
          String str1 = CommentBlog.this.mUsername;
          String str2 = CommentBlog.this.mPassword;
          User localUser1 = localRPCHelper1.login(str1, str2);
          localCommentBlog1.mUser = localUser1;
          if ((CommentBlog.this.mUser.gsid != null) && (CommentBlog.this.mUser.uid != null) && (CommentBlog.this.mUser.nick != null));
        }
        Object[] arrayOfObject4;
        for (localObject = null; ; localObject = (List)arrayOfObject4[1])
        {
          return localObject;
          User localUser2 = CommentBlog.this.mUser;
          String str3 = CommentBlog.this.mCacheDir;
          CommentBlog localCommentBlog2 = CommentBlog.this;
          Utils.saveUserFile(localUser2, str3, localCommentBlog2);
          Object[] arrayOfObject3 = new Object[1];
          Integer localInteger2 = Integer.valueOf(2);
          arrayOfObject3[0] = localInteger2;
          publishProgress(arrayOfObject3);
          RPCHelper localRPCHelper2 = RPCHelper.getInstance(CommentBlog.this);
          User localUser3 = CommentBlog.this.mUser;
          String str4 = CommentBlog.this.mBlogUid;
          String str5 = CommentBlog.this.mBlogId;
          arrayOfObject4 = localRPCHelper2.getAttCommentList(localUser3, str4, str5, i, 20);
          Object[] arrayOfObject5 = new Object[1];
          Integer localInteger3 = Integer.valueOf(3);
          arrayOfObject5[0] = localInteger3;
          publishProgress(arrayOfObject5);
          localObject = CommentBlog.this;
          if (arrayOfObject4[0] == 0)
            break;
          k = ((Integer)arrayOfObject4[0]).intValue();
          ((CommentBlog)localObject).mTotal = k;
        }
      }
      catch (RPCHelper.HttpException localHttpException)
      {
        while (true)
        {
          Object localObject = null;
          continue;
          int k = 0;
        }
      }
    }

    protected void onCancelled()
    {
      if ((CommentBlog.this.mList == null) || (CommentBlog.this.mList.size() == 0))
        CommentBlog.this.mLvCmt.setVisibility(4);
      while (true)
      {
        CommentBlog.this.mTaskFree = 1;
        return;
        ((CommentBlog.WeiboCmtListAdapter)CommentBlog.this.mLvCmt.getAdapter()).refresh();
        CommentBlog.this.mLvCmt.setVisibility(0);
        CommentBlog.this.mLvCmt.setFocusable(1);
        CommentBlog.this.mLvCmt.setFocusableInTouchMode(1);
      }
    }

    protected void onPostExecute(List<Comment> paramList)
    {
      CommentBlog.this.closeFthProgress(paramList);
      CommentBlog.this.setAppTitle();
      CommentBlog.this.mTaskFree = 1;
      if (CommentBlog.this.mPgToast != null)
        CommentBlog.this.mPgToast.cancel();
    }

    protected void onPreExecute()
    {
      CommentBlog.this.mTaskFree = 0;
      CommentBlog.this.showFthProgress();
    }

    protected void onProgressUpdate(Integer[] paramArrayOfInteger)
    {
      switch (paramArrayOfInteger[0].intValue())
      {
      case 1:
      default:
      case 2:
      }
      while (true)
      {
        return;
        CommentBlog.this.setAppTitle();
      }
    }
  }

  class PostCommentTask extends AsyncTask<Void, Void, Boolean>
  {
    private PostCommentTask()
    {
    }

    protected Boolean doInBackground(Void[] paramArrayOfVoid)
    {
      try
      {
        if (CommentBlog.this.mUser == null)
        {
          CommentBlog localCommentBlog1 = CommentBlog.this;
          RPCHelper localRPCHelper1 = RPCHelper.getInstance(CommentBlog.this);
          String str1 = CommentBlog.this.mUsername;
          String str2 = CommentBlog.this.mPassword;
          User localUser1 = localRPCHelper1.login(str1, str2);
          localCommentBlog1.mUser = localUser1;
          if ((CommentBlog.this.mUser.gsid == null) || (CommentBlog.this.mUser.uid == null) || (CommentBlog.this.mUser.nick == null))
          {
            localBoolean = Boolean.valueOf(0);
            return localBoolean;
          }
          User localUser2 = CommentBlog.this.mUser;
          String str3 = CommentBlog.this.mCacheDir;
          CommentBlog localCommentBlog2 = CommentBlog.this;
          Utils.saveUserFile(localUser2, str3, localCommentBlog2);
        }
        if ((CommentBlog.this.mSubString != null) && (CommentBlog.this.mComment != null) && (CommentBlog.this.mSubString.length() != 0) && (CommentBlog.this.mComment.length() != 0))
        {
          CommentBlog localCommentBlog3 = CommentBlog.this;
          String str4 = CommentBlog.this.mComment;
          String str5 = CommentBlog.this.mSubString;
          String str6 = str4.replace(str5, "");
          localCommentBlog3.mComment = str6;
        }
        if (CommentBlog.this.mFlag == 2)
          if (CommentBlog.this.mCurCmt != null)
          {
            RPCHelper localRPCHelper2 = RPCHelper.getInstance(CommentBlog.this);
            User localUser3 = CommentBlog.this.mUser;
            String str7 = CommentBlog.this.mBlogUid;
            String str8 = CommentBlog.this.mBlogId;
            String str9 = CommentBlog.this.mCurCmt.cmtuid;
            String str10 = CommentBlog.this.mCurCmt.cmtid;
            String str11 = CommentBlog.this.mComment;
            boolean bool1 = CommentBlog.this.isAsNewMblog;
            boolean bool2 = localRPCHelper2.replyComment(localUser3, str7, str8, str9, str10, str11, bool1);
            label347: CommentBlog.this.mFlag = 1;
          }
        while (true)
        {
          localBoolean = Boolean.valueOf(1);
          break;
          RPCHelper localRPCHelper3 = RPCHelper.getInstance(CommentBlog.this);
          User localUser4 = CommentBlog.this.mUser;
          String str12 = CommentBlog.this.mBlogUid;
          String str13 = CommentBlog.this.mBlogId;
          String str14 = CommentBlog.this.mPassCommentUID;
          String str15 = CommentBlog.this.mPassCommentId;
          String str16 = CommentBlog.this.mComment;
          boolean bool3 = CommentBlog.this.isAsNewMblog;
          boolean bool4 = localRPCHelper3.replyComment(localUser4, str12, str13, str14, str15, str16, bool3);
          break label347;
          RPCHelper localRPCHelper4 = RPCHelper.getInstance(CommentBlog.this);
          User localUser5 = CommentBlog.this.mUser;
          String str17 = CommentBlog.this.mBlogUid;
          String str18 = CommentBlog.this.mBlogId;
          String str19 = CommentBlog.this.mComment;
          boolean bool5 = CommentBlog.this.isAsNewMblog;
          boolean bool6 = localRPCHelper4.addComment(localUser5, str17, str18, str19, bool5);
          boolean bool7 = bool6;
        }
      }
      catch (RPCHelper.HttpException localHttpException)
      {
        while (true)
          Boolean localBoolean = Boolean.valueOf(0);
      }
    }

    protected void onCancelled()
    {
      CommentBlog.this.mPostTaskFree = 1;
    }

    protected void onPostExecute(Boolean paramBoolean)
    {
      CommentBlog.this.mPostTaskFree = 1;
      CommentBlog.this.closeProgress(paramBoolean);
      if (CommentBlog.this.mPgToast != null)
        CommentBlog.this.mPgToast.cancel();
    }

    protected void onPreExecute()
    {
      CommentBlog.this.mPostTaskFree = 0;
    }

    protected void onProgressUpdate(Void[] paramArrayOfVoid)
    {
    }
  }

  class WeiboCmtListAdapter extends BaseAdapter
  {
    public WeiboCmtListAdapter()
    {
    }

    public int getCount()
    {
      if (CommentBlog.this.mList == null);
      for (int i = 0; ; i = CommentBlog.this.mList.size() + 1)
        return i;
    }

    public Object getItem(int paramInt)
    {
      return Integer.valueOf(paramInt);
    }

    public long getItemId(int paramInt)
    {
      return paramInt;
    }

    public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
    {
      int i = CommentBlog.this.mList.size();
      Object localObject1;
      if (paramInt == i)
      {
        CommentBlog localCommentBlog1 = CommentBlog.this;
        localObject1 = new TextView(localCommentBlog1);
        ((TextView)localObject1).setText(2131427442);
        ((TextView)localObject1).setGravity(17);
        ((TextView)localObject1).setTextSize(18.0F);
        ((TextView)localObject1).setTextColor(-16777216);
        ((TextView)localObject1).setPadding(15, 15, 15, 15);
        int j = CommentBlog.this.mList.size();
        int k = CommentBlog.this.mTotal;
        if (j >= k)
          ((View)localObject1).setVisibility(4);
      }
      while (true)
      {
        return localObject1;
        ((View)localObject1).setVisibility(0);
        continue;
        if (paramView == null)
        {
          CommentBlog localCommentBlog2 = CommentBlog.this;
          Comment localComment1 = (Comment)CommentBlog.this.mList.get(paramInt);
          localObject1 = new CommentItemView(localCommentBlog2, localComment1);
          continue;
        }
        localObject1 = paramView;
        try
        {
          CommentItemView localCommentItemView = (CommentItemView)localObject1;
          Object localObject2 = CommentBlog.this.mList.get(paramInt);
          localCommentItemView.update(localObject2);
        }
        catch (Exception localException)
        {
          CommentBlog localCommentBlog3 = CommentBlog.this;
          Comment localComment2 = (Comment)CommentBlog.this.mList.get(paramInt);
          localObject1 = new CommentItemView(localCommentBlog3, localComment2);
        }
      }
    }

    public void refresh()
    {
      notifyDataSetChanged();
    }
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     com.sina.weibo.CommentBlog
 * JD-Core Version:    0.6.0
 */